// 1.5 Random state
// 生成随机状态值

use rand::{Rng,thread_rng};
use base64::{engine::general_purpose::URL_SAFE, Engine};


// 标记函数是否在之前启动过
// true若启动过则从静态值中获取
// false若未启动过则生成随机数并存入静态值中
static mut status:bool = false;
static mut value:String = String::new();
pub fn get_random_state() -> String {
    unsafe {
        if (!status) {
        // 没启动过
        let mut buffer = [0u8;64];
        thread_rng().fill(&mut buffer);
        value = URL_SAFE.encode(buffer);
        status = true;
        return value.clone();
    } else {
        return value.clone();
    }
    }
    
    
}